package servlet;

import dao.RescheduleNotificationsDao;
import dao.impl.RescheduleNotificationsDaoImpl;
import entity.RescheduleNotifications;
import utils.ResponseResult;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "RescheduleServlet", urlPatterns = "/bigProjects/RescheduleServlet")


//关于通知的接口⭐⭐⭐⭐⭐
// (关于通知,为了简化系统 ;只有用户可以收到通知,医生没有该功能)
public class RescheduleServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        RescheduleNotificationsDao rescheduleNotificationsDao = new RescheduleNotificationsDaoImpl();
        resp.setContentType("application/json");
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        Integer userId = Integer.valueOf(req.getParameter("userId"));

        List<RescheduleNotifications> list = rescheduleNotificationsDao.queryAllById(userId);
        resp.getWriter().write(ResponseResult.success(list).toString());
    }


    @Override
    protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        RescheduleNotificationsDao rescheduleNotificationsDao = new RescheduleNotificationsDaoImpl();
        resp.setContentType("application/json");
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        Integer id = Integer.valueOf(req.getParameter("id"));//DELETE方法可以用这个接收参数

        int i = rescheduleNotificationsDao.deleteById(id);
        if (i > 0) resp.getWriter().write(ResponseResult.success().toString());
        else resp.getWriter().write(ResponseResult.failure("删除失败").toString());
    }
}
